package igloo.ui;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.JPanel;

import net.miginfocom.swing.MigLayout;

import org.jdesktop.swingx.JXBusyLabel;

@SuppressWarnings("serial")
public class BusyPanel extends JPanel
{
    private JLabel mTextLabel;
    private JLabel mSubtextLabel;

    public BusyPanel()
    {
        setLayout(new MigLayout("center, fill"));
        setOpaque(false);

        JXBusyLabel busyLabel = new JXBusyLabel(new Dimension(150, 150));
        busyLabel.getBusyPainter().setPoints(10);
        busyLabel.setOpaque(false);

        add(busyLabel, "wrap");
        add(getTextLabel(), "growx, gaptop 10, wrap");
        add(getSubtextLabel(), "growx, gaptop 10, wrap");
        busyLabel.setBusy(true);
    }

    public void setText(String text)
    {
        getTextLabel().setText(text);
    }

    public void setSubtext(String text)
    {
        getSubtextLabel().setText(text);
    }

    private JLabel getTextLabel()
    {
        if(mTextLabel == null)
        {
            mTextLabel = new JLabel("", JLabel.CENTER);
            mTextLabel.setFont(mTextLabel.getFont().deriveFont(16f));
            mTextLabel.setForeground(Color.WHITE);
            mTextLabel.setOpaque(false);
        }

        return mTextLabel;
    }

    private JLabel getSubtextLabel()
    {
        if(mSubtextLabel == null)
        {
            mSubtextLabel = new JLabel("", JLabel.CENTER);
            mSubtextLabel.setFont(mSubtextLabel.getFont().deriveFont(10f));
            mSubtextLabel.setForeground(Color.WHITE);
            mSubtextLabel.setOpaque(false);
        }

        return mSubtextLabel;
    }
}
